/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.network.topo.attachment;

import java.awt.Color;
import java.awt.Font;
import java.beans.PropertyChangeEvent;
import java.util.Vector;

import twaver.TUIManager;
import twaver.TWaverConst;
import twaver.TWaverUtil;
import twaver.chart.BarChart;
import twaver.chart.Item;
import twaver.network.ui.ComponentAttachment;
import twaver.network.ui.ElementUI;

public class BarAttachment extends ComponentAttachment{

	private BarChart bar;
	private Item xItem;
	private Item yItem;
	
	public BarAttachment(String name, ElementUI ui) {
		super(name, ui);
		
		xItem = new Item("x", element.getX(), Color.RED);
		yItem = new Item("y", element.getY(), Color.BLUE);
		Vector items = new Vector();
        items.addElement(xItem);
        items.addElement(yItem);
        bar = new BarChart(items, "Coordinate", Color.WHITE);
        bar.setValueTextColor(Color.WHITE);
        bar.setValueTextFont(TWaverUtil.getFont(Font.ITALIC, 10));
        bar.setBackground(Color.BLACK);
        bar.setForeground(Color.WHITE);

        this.setMinimizedIcon(TWaverUtil.getImageIcon("/demo/network/topo/attachment/bar.png"));
        this.setMinimizable(true);
        this.setWidth(120);
        this.setHeight(120);
        this.setBorderVisible(true);
        this.setBorderColor(Color.YELLOW);
        this.setBorderStroke(TUIManager.getStrokeByType(TWaverConst.STROKE_ZIGZAG_NARROWEST));
        this.setPosition(TWaverConst.POSITION_RIGHT);
        this.setXOffset(4);
		this.setComponent(bar);
	}

	public void elementPropertyChange(PropertyChangeEvent evt) {
		super.elementPropertyChange(evt);
		if(evt.getPropertyName().equals(TWaverConst.PROPERTYNAME_LOCATION)){
			xItem.setValue(element.getX());
			yItem.setValue(element.getY());
		}
	}
	
    public boolean isShownOnTop(){
    	return true;
    }

}